package com.liming.cartype.webapp.wicket.page;

import com.liming.cartype.api.biz.ICarTypeService;
import com.liming.cartype.api.biz.IParameterService;
import com.liming.cartype.api.persistence.impl.CarTypeBeanImpl;
import com.liming.cartype.api.persistence.impl.ParameterBeanImpl;
import com.liming.core.web.wicket.BasePage;
import org.apache.aries.blueprint.annotation.Reference;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;

/**
 * @类描述：车型参数管理
 * @创建人：wangkr
 * @创建时间：2014-03-29 下午3:17
 * @修改人：
 * @修改时间：
 * @修改备注：
 */

public class CartypeParameters extends BasePage {
    @Named
    @Inject
    @Reference(id = "parameterService", serviceInterface = IParameterService.class)
    private IParameterService parameterService;

    @Named
    @Inject
    @Reference(id = "carTypeService", serviceInterface = ICarTypeService.class)
    private ICarTypeService carTypeService;

    final RepeatingView parametersPanel = new RepeatingView("parametersPanel");
    final RepeatingView parametersForm = new RepeatingView("parametersForm");
    public CartypeParameters (PageParameters param){
        final String carTypeId = param.get("carTypeId").toString();
        CarTypeBeanImpl carTypeBean = carTypeService.findCarType(carTypeId);
        //新增的表单
        AddParameterForm addParameterForm = new AddParameterForm(parametersForm.newChildId(),carTypeBean);
        parametersForm.add(addParameterForm);
        add(parametersForm);

        //初始化数据
        List<ParameterBeanImpl> parameterBeanList = parameterService.getAllParameter();
        for(ParameterBeanImpl parameterBean : parameterBeanList){
            parametersPanel.add(new ParameterTable(parametersPanel.newChildId(),parameterBean));
    }
        add(parametersPanel);
    }
}


